package mall.service;

import mall.core.jdbc.Page;
import mall.entity.Category;
import mall.repository.CategoryDao;

import java.util.List;

/**
 * @author xf07b1
 * @wechat xf07b1
 */
public class CategoryService {
    private final CategoryDao categoryDao = new CategoryDao();

    public List<Category> list() {
        return categoryDao.selectList(new Category());
    }

    public List<Category> list(String name) {
        Category category = new Category();
        category.setName(name);
        return categoryDao.selectList(category);
    }

    public List<Category> list(Category category) {
        return categoryDao.selectList(category);
    }

    public Category getById(int id) {
        return categoryDao.selectById(id);
    }

    public int update(Category category) {
        return categoryDao.updateById(category);
    }

    public int add(Category category) {
        return categoryDao.insert(category);
    }

    public int deleteById(int id) {
        return categoryDao.deleteById(id);
    }
    public Page<Category> page(Page<Category> page, Category category) {
        Integer total = categoryDao.count(category);
        List<Category> list = categoryDao.selectList(category,page.getOffset(),page.getPageSize());
        page.setTotal(total);
        page.setList(list);
        return page;
    }
}
